package com.navi.loaddata.loadService.impl.teg2Data;

import com.navi.loaddata.core.errorLog.ErrorCode;
import com.navi.loaddata.core.etlException.ETLException2;
import com.navi.loaddata.core.gpEntity.WppTegStatistic2;
import com.navi.loaddata.core.oracleEntity.array.EtlArrayGlassV;
import com.navi.loaddata.core.oracleEntity.array.EtlArrayIvCurveV;
import com.navi.loaddata.core.util.LoggerUtil;
import com.navi.loaddata.core.util.ProcessUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author jay
 */
@Service
public class ProcessTeg2DataService {
    private static final Logger logger = LoggerFactory.getLogger(ProcessTeg2DataService.class);

    public EtlArrayIvCurveV processTeg2(WppTegStatistic2 ivCurve) throws Exception {
        EtlArrayIvCurveV ivCurveEntity = new EtlArrayIvCurveV();
        try {
            ivCurveEntity.setStepId(ivCurve.getOpeId());
            ivCurveEntity.setGlassId(ivCurve.getGlassId());
            ivCurveEntity.setGlassEndTime(ivCurve.getProcEnd());
            ivCurveEntity.setParamCollection(ivCurve.getRecipeId() + "SWEEP");
            ivCurveEntity.setParamName("iv_curve");
            ivCurveEntity.setSiteName(ivCurve.getEt());
            ivCurveEntity.setSeqNo(Long.valueOf(ivCurve.getSeqId()));
            ivCurveEntity.setVd(Long.valueOf(10));
            ivCurveEntity.setVg(ProcessUtil.getDouble(ivCurve.getVg()));
            ivCurveEntity.setId(ProcessUtil.getDouble(ivCurve.getId1()));

        }catch (Exception e){
            throw new ETLException2(ErrorCode.ERROR_PROCESS_GP2ORA_ARRAY_IvCurve,e);
        }

        return ivCurveEntity;
    }

    public EtlArrayGlassV processGlass(WppTegStatistic2 teg2) throws Exception {
        EtlArrayGlassV glassEntity = new EtlArrayGlassV();
        try {
            glassEntity.setStepId(ProcessUtil.processString(teg2.getOpeId()));
            glassEntity.setGlassId(ProcessUtil.processString(teg2.getGlassId()));
            Date procEndTime = new Date(teg2.getProcEnd().getTime());
            glassEntity.setGlassEndTime(procEndTime);
            glassEntity.setGlassStartTime(teg2.getProcStart());
            glassEntity.setProductId(ProcessUtil.processString(teg2.getProdId()));
            glassEntity.setProductVersion(null);
            glassEntity.setRouteId(null);
            glassEntity.setLotId(ProcessUtil.processString(teg2.getLotId()));
            glassEntity.setEquipId(ProcessUtil.processString(teg2.getEqptId()));
            glassEntity.setRunMode(null);
            glassEntity.setRecipeId(ProcessUtil.processString(teg2.getRecipeId()));
            glassEntity.setSubEquipId(null);
//            glassEntity.setOperatorId(ProcessUtil.processString(teg2.getOperatorId()));
//            glassEntity.setCstId(ProcessUtil.processString(glass.getCrrId()));
            if (procEndTime.getHours() >= 8 && procEndTime.getHours() <= 20) {
                glassEntity.setTaShift("D");
            } else {
                glassEntity.setTaShift("N");
            }
//            glassEntity.setLotType(ProcessUtil.processString(teg2.getLotType()));
            glassEntity.setOwnerId(ProcessUtil.processString(teg2.getOwner()));
            //  glassEntity.setOwnerType(); //待处理
            glassEntity.setSlotNo(ProcessUtil.processString(teg2.getSlotId()));
//            glassEntity.setAbnormalFlag(ProcessUtil.processString(teg2.getAbnFlg()));
//            glassEntity.setMesLinkKry(ProcessUtil.processString(teg2.getMesLinkKey()));
            // glassEntity.setSamplingFlag(); //待处理
//            glassEntity.setGlassJudge(ProcessUtil.processString(glass.getGlassJge()));
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date1 = teg2.getProcEnd();
            Date date2 = teg2.getProcStart();
            glassEntity.setProcessTime(date1.getTime() - date2.getTime());
//            glassEntity.setTactTime(ProcessUtil.getNumI(glass.getTactTime()));
//            glassEntity.setTotalDftCount(ProcessUtil.getNumI(glass.getGlassDefectCnt()));
//            glassEntity.setTotalImageCount(ProcessUtil.getNumI(glass.getGlassImgCnt()));
//            //  glassEntity.setTotalReprDftQty(); //待处理
//            glassEntity.setLcvdReprDftQty(ProcessUtil.getNumI(glass.getGlassLcvdRepDefectCnt()));
//            glassEntity.setBackSideDftQty(ProcessUtil.getNumI(glass.getGlassBackDefectCnt()));
//            glassEntity.setTestKetDftQty(ProcessUtil.getNumI(glass.getGlassTestKeyDefectCnt()));
//            glassEntity.setAftStkDftQty(ProcessUtil.getNumI(glass.getGlassAfterStackDefectCnt()));
//            glassEntity.setInkReprDftQty(ProcessUtil.getNumI(glass.getGlassInkRepDefectCnt()));
//            glassEntity.setPnlCapDftQty(ProcessUtil.getNumI(glass.getGlassCaptureDefectCnt()));
//            glassEntity.setTapReprDftQty(ProcessUtil.getNumI(glass.getGlassTapeRepDefectCnt()));
//            glassEntity.setLsrReprDftQty(ProcessUtil.getNumI(glass.getGlassLaserRepDefectCnt()));
//            glassEntity.setoDftQty(ProcessUtil.getNumI(glass.getGlassOSizeCnt()));
//            glassEntity.setlDftQty(ProcessUtil.getNumI(glass.getGlassLSizeCnt()));
//            glassEntity.setmDftQty(ProcessUtil.getNumI(glass.getGlassMSizeCnt()));
//            glassEntity.setsDftQty(ProcessUtil.getNumI(glass.getGlassSSizeCnt()));
//            glassEntity.setBrightDftQty(ProcessUtil.getNumI(glass.getGlassBrightDefectCnt()));
//            glassEntity.setWriteDftQty(ProcessUtil.getNum(glass.getWorkOrder()));
//            glassEntity.setGrayDftQty(ProcessUtil.getNumI(glass.getGlassGrayDefectCnt()));
//            glassEntity.setBlackDftQty(ProcessUtil.getNumI(glass.getGlassDarkDefectCnt()));
//            glassEntity.setScanAlignMark1Flg(ProcessUtil.getNum(glass.getScanAlignMark1Flg()));
//            glassEntity.setScanAlignMark2Flg(ProcessUtil.getNum(glass.getScanAlignMark2Flg()));
//            glassEntity.setScanAlignMark1X(ProcessUtil.getNum(glass.getScanAlignMark1XCoord()));
//            glassEntity.setScanAlignMark1Y(ProcessUtil.getNum(glass.getScanAlignMark1YCoord()));
//            glassEntity.setScanAlignMark2X(ProcessUtil.getNum(glass.getScanAlignMark2XCoord()));
//            glassEntity.setScanAlignMark2Y(ProcessUtil.getNum(glass.getScanAlignMark2YCoord()));
//            glassEntity.setCaptureAlignMark1Flg(ProcessUtil.getNum(glass.getCaptureAlignMark1Flg()));
//            glassEntity.setCaptureAlignMark2Flg(ProcessUtil.getNum(glass.getCaptureAlignMark2Flg()));
//            glassEntity.setCaptureAlignMark1X(ProcessUtil.getNum(glass.getCaptureAlignMark1XCoord()));
//            glassEntity.setCaptureAlignMark1Y(ProcessUtil.getNum(glass.getCaptureAlignMark1YCoord()));
//            glassEntity.setCaptureAlignMark2X(ProcessUtil.getNum(glass.getCaptureAlignMark2XCoord()));
//            glassEntity.setCaptureAlignMark2Y(ProcessUtil.getNum(glass.getCaptureAlignMark2YCoord()));
//            glassEntity.setResolRvHead1(ProcessUtil.processString(glass.getRewHeadResolution1()));
//            glassEntity.setResolRvHead2(ProcessUtil.processString(glass.getRewHeadResolution2()));
//            glassEntity.setResolRvHead3(ProcessUtil.processString(glass.getRewHeadResolution3()));
//            glassEntity.setResolRvHead4(ProcessUtil.processString(glass.getRewHeadResolution4()));
//            glassEntity.setResolRvHead5(ProcessUtil.processString(glass.getRewHeadResolution5()));
//            glassEntity.setResolRvHead6(ProcessUtil.processString(glass.getRewHeadResolution6()));
//            glassEntity.setCaptureSize(ProcessUtil.processString(glass.getCaptureSize()));
//            glassEntity.setProbeCardId(ProcessUtil.processString(glass.getProbeCardId()));
//            if(!StringUtils.isEmpty(glass.getRewkCnt())) {
//                glassEntity.setReworkCnt(String.valueOf(glass.getRewkCnt()));
//            }else {
//                glassEntity.setReworkCnt("-1");
//            }
        }catch (Exception e){
            throw new ETLException2(ErrorCode.ERROR_PROCESS_GP2ORA_ARRAY_GLASS,e);
        }
        return glassEntity;

    }


}

